package com.example.redistest.ThreadDemo;

/**
 * synchronized关键字同步,数据安全高于程序性能
 *
 */
public class Processor implements Runnable {
    private Bank bank;
    public Processor (Bank bank){
        this.bank = bank;
    }
    @Override
    public void run() {
        while (true){
            //执行取款操作
            bank.takeMoney(1000.0);
            System.out.println(Thread.currentThread().getName()+":::"+bank.getName()+"取款1000.0成功,余额: "+bank.getBlanance());
        }
    }

    public static void main(String[] args) {
        Bank bank = new Bank("银行1",5000.0);
        //Bank bank1 = new Bank("银行2",5000.0);
        //Bank bank2 = new Bank("银行3",5000.0);
        Thread thread1 = new Thread(new Processor(bank));
        Thread thread2 = new Thread(new Processor6(bank));
       // Thread thread3 = new Thread(new Processor(bank));
        thread1.start();
        thread2.start();
       // thread3.start();
    }

}
